package com.ruoyi.web.controller.vip;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ruoyi.common.core.domain.entity.TotalResultMap;
import com.ruoyi.common.utils.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.vip.VsDramasVipOrder;
import com.ruoyi.system.service.vip.IVsDramasVipOrderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
/**
 * This file is part of 南阳迈特网络科技有限公司.
 * @company  南阳迈特网络科技有限公司
 * @link     https://www.nymaite.com
 * @document https://product.nymaite.cn
 * @contact  service@nymaite.com
 * @author nymaite
 */
/**
 * VIP订单Controller
 * 
 * @author zzx
 * @date 2024-04-25
 */
@Api(tags = "VIP订单")
@RestController
@RequestMapping("/vip/order")
public class VsDramasVipOrderController extends BaseController
{
    @Autowired
    private IVsDramasVipOrderService vsDramasVipOrderService;

    /**
     * 查询VIP订单列表
     */
    @ApiOperation("查询VIP订单列表")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "userId", value = "userId", required=true),
            @ApiImplicitParam(name = "pageNum", value = "页数", required=true),
            @ApiImplicitParam(name = "pageSize", value = "数量", required=true)
    })
    @GetMapping("/list")
    public TableDataInfo list(VsDramasVipOrder vsDramasVipOrder)
    {
        startPage();
        List<VsDramasVipOrder> list = vsDramasVipOrderService.selectVsDramasVipOrderList(vsDramasVipOrder);
        return getDataTable(list);
    }

    /**
     * 导出VIP订单列表
     */
//    @ApiOperation("导出VIP订单列表")
    @Log(title = "VIP订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VsDramasVipOrder vsDramasVipOrder)
    {
        List<VsDramasVipOrder> list = vsDramasVipOrderService.selectVsDramasVipOrderList(vsDramasVipOrder);
        ExcelUtil<VsDramasVipOrder> util = new ExcelUtil<VsDramasVipOrder>(VsDramasVipOrder.class);
        util.exportExcel(response, list, "VIP订单数据");
    }

    /**
     * 获取VIP订单详细信息
     */
    @ApiOperation("获取VIP订单详细信息")
    @ApiImplicitParam(name = "id", value = "订单id", required=true)
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(vsDramasVipOrderService.selectVsDramasVipOrderById(id));
    }

    /**
     * 新增VIP订单
     */
    @ApiOperation("新增VIP订单")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "vipId", value = "vipId", required=true),
            @ApiImplicitParam(name = "langId", value = "langId", required=true),
            @ApiImplicitParam(name = "totalFee", value = "订单金额", required=true),
            @ApiImplicitParam(name = "platform", value = "平台", required=true)
    })
//    @ApiOperationSupport(includeParameters = {"vsDramasVipOrder.vipId","vsDramasVipOrder.langId","vsDramasVipOrder.totalFee","vsDramasVipOrder.platform"})
    @Log(title = "VIP订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VsDramasVipOrder vsDramasVipOrder, HttpServletRequest request)
    {
        if ("guest".equals(getLoginUser().getVsUser().getMode())) {
            return error();
        }
        if (!StringUtils.isEmpty(request.getHeader("Lang-Id"))) {
            Integer integer = Integer.valueOf(request.getHeader("Lang-Id"));
            vsDramasVipOrder.setLangId(integer);
        }
        String orderSn = vsDramasVipOrderService.insertVsDramasVipOrder(vsDramasVipOrder);
        if ("err".equals(orderSn)) {
            return error("创建订单失败！");
        }
        Map map = new HashMap<>();
        map.put("orderSn", orderSn);
        return success(map);
    }

    /**
     * 修改VIP订单
     */
//    @ApiOperation("修改VIP订单")
    @Log(title = "VIP订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VsDramasVipOrder vsDramasVipOrder)
    {
        return toAjax(vsDramasVipOrderService.updateVsDramasVipOrder(vsDramasVipOrder));
    }

    /**
     * 删除VIP订单
     */
//    @ApiOperation("删除VIP订单")
    @Log(title = "VIP订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(vsDramasVipOrderService.deleteVsDramasVipOrderByIds(ids));
    }

    /**
     * 查询VIP订单列表
     */
//    @ApiOperation("查询VIP订单总和")
    @PostMapping("/selectCount")
    public AjaxResult selectCount(VsDramasVipOrder vsDramasVipOrder)
    {
        TotalResultMap totalResultMap = vsDramasVipOrderService.selectCount(vsDramasVipOrder);
        return AjaxResult.success(totalResultMap);
    }

}
